package grpc

import (
	"base_server/internal/models/customer_registration"
	"context"
	"jihe.common/protos/base_server/proto"
)

func (s *Server) BaseCreateCustomerRegistration(c context.Context, in *proto.BaseCustomerRegistration) (ret *proto.BaseCustomerRegistration, err error) {
	ret = new(proto.BaseCustomerRegistration)
	customerRegistrationTbl := customer_registration.NewModel(s.Pgsql.Get())
	ret.Id, err = customerRegistrationTbl.Create(in)
	return
}

func (s *Server) BaseUpdateCustomerRegistration(c context.Context, in *proto.BaseCustomerRegistration) (ret *proto.BaseNull, err error) {
	customerRegistrationTbl := customer_registration.NewModel(s.Pgsql.Get())
	err = customerRegistrationTbl.Update(in)
	ret = &proto.BaseNull{}
	return
}

func (s *Server) BaseUpdateNeedObjByNeedId(c context.Context, in *proto.BaseCustomerRegistration) (ret *proto.BaseNull, err error) {
	customerRegistrationTbl := customer_registration.NewModel(s.Pgsql.Get())
	err = customerRegistrationTbl.UpdateObjIsNull(in.Id)
	ret = &proto.BaseNull{}
	return
}

func (s *Server) BaseGetCustomerRegistrationList(c context.Context, in *proto.BaseGetCustomerRegistrationListReq) (ret *proto.BaseGetCustomerRegistrationListRes, err error) {
	customerRegistrationTbl := customer_registration.NewModel(s.Pgsql.Get())
	ret = new(proto.BaseGetCustomerRegistrationListRes)
	ret.PageSize = in.PageSize
	in.Page = in.Page - 1
	ret.List, ret.Total, err = customerRegistrationTbl.GetList(in)
	if err != nil {
		return
	}
	ret.Page = in.Page + 1
	return
}

func (s *Server) BaseGetCustomerRegistrationDetail(c context.Context, in *proto.BaseCustomerRegistration) (ret *proto.BaseCustomerRegistration, err error) {
	customerRegistrationTbl := customer_registration.NewModel(s.Pgsql.Get())
	return customerRegistrationTbl.GetDetailById(in.Id)
}
